import { getStorage,setStorage } from '@/utils/tools'
import { defineStore } from 'pinia'
import { IAdmin, IAdminInfo } from '@/types'

export const adminStore = defineStore({
  id: 'app-admin',
  state: (): IAdminInfo => ({
    admin: getStorage('admin'),
    token: getStorage('token'),
  }),
  actions: {
    setAdmin(value: any) {
      setStorage('admin',value);
      this.admin = value
    },
    setToken(value: string,expire:0) {
      setStorage('token',value,expire);
      this.token = value
    },
  },
  getters: {
    curAdmin(): IAdmin {
      return this.admin
    },
    curAccount(): string {
      return this.admin.account
    },
    curAdminAvatar(): string {
      return this.admin.avatar
    },
    curToken(): string {
      return this.token
    },
    getCacheInfo(): any{
      let data = getStorage('admin');
      if(data) this.admin = data
      return this.admin;
    },
    init(){
      
    }
  },
})
